package com.gyms.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.classic.okhttp.beans.HVCardBean;
import com.gyms.R;
import com.gyms.base.BaseActivity;
import com.gyms.constant.Constants;
import com.gyms.manager.TitleManager;
import com.gyms.view.bottomview.ShareDialog;
import com.umeng.socialize.UMShareAPI;

import butterknife.BindView;
import constant.PicSplit;
import utils.DecimalUtils;
import utils.StringUtils;

/**
 * 卡卷详情
 * ltx
 */

public class CouponDetailActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_coupon_detail_name)
    TextView mTvCouponDetailName;//卡卷名称
    @BindView(R.id.tv_coupon_detail_money)
    TextView mTvCouponDetailMoney;//卡卷减额
    @BindView(R.id.tv_coupon_content)
    TextView mTvCouponContent;//卡卷详情
     @BindView(R.id.ll_coupon_bg)
     LinearLayout mLlCouponBg;//卡卷详情
    private ShareDialog mShareDialog;
    private String mCouponId;
    private String mCouponName;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_coupon_detail;
    }

    @Override
    protected void setTitleTheme() {
        mTheme = TitleManager.TitleTheme.White;
    }

    @Override
    protected void initView() {
        setTitle("卡卷详情");
        setBack();
        initData();
    }

    private void initData() {
        Bundle mBundle=getIntent().getExtras();
        if(null!=mBundle){
            HVCardBean mHVCardBean = (com.classic.okhttp.beans.HVCardBean) mBundle.getSerializable(Constants.KEY_CARD_BEAN);
            if(!StringUtils.isNull(mHVCardBean)){
                mCouponId=mHVCardBean.couponId;
                doFullView(mHVCardBean);
            }
        }
    }

    private void doInitView() {
        ImageView ivShare = mTitleManager.setRightViewR(R.mipmap.icon_fenxiang);
        ivShare.setOnClickListener(this);
    }

    @Override
    protected void setListener() {
    }

    @Override
    protected void processLogic() {
    }


    /**
     *
     * @param response 详情bean
     */

    private void doFullView(HVCardBean response) {
        mCouponName=response.getCouponName();
        mTvCouponDetailName.setText(mCouponName);
        mTvCouponContent.setText(response.getCouponDescription());
        mTvCouponDetailMoney.setText(DecimalUtils.setPriceStyle(mContext,response.getMoney(),R.dimen.price_text_size_50,R.dimen.price_text_size_36,true));
        if(response.exclusive){//专属不能分享
            mLlCouponBg.setBackgroundColor(ContextCompat.getColor(mContext,R.color.c_06C1AE));
            mTvCouponDetailMoney.setTextColor(ContextCompat.getColor(mContext,R.color.c_06C1AE));
        }else{
            mLlCouponBg.setBackgroundColor( ContextCompat.getColor(mContext,R.color.c_FF9E00));
            mTvCouponDetailMoney.setTextColor( ContextCompat.getColor(mContext,R.color.c_FF9E00));
            doInitView();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_img_right_right:
                if (null == mShareDialog) {
                    mShareDialog = new ShareDialog(this, R.style.BottomToTopAnim);
                    mShareDialog.setTitle(PicSplit.makeShareTitle(mCouponName));
                    String mShareGymUrl= PicSplit.makeShareUrl(PicSplit.S_COUPON_ID,mCouponId,null,null);
                    mShareDialog.setTagUrl(mShareGymUrl);
                    Log.e("shareUrl",mShareGymUrl);
                    mShareDialog.setShareContent(PicSplit.S_CARD_SHARE_CONTENT);
                }
                mShareDialog.show();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        UMShareAPI.get(this).release();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }
}
